//
//  admanager.m
//  admanager
//
//  Created by chit on 4/3/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "oc_np_manager.h"
#import "c_np_manager.h"
#include "twodstaruikitdelegate.h"


@implementation OC_NPmanager


- (void) Init:(NSString*) Key
{
    
    // Register for push notifications
    [[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeSound |
     UIRemoteNotificationTypeAlert];
    
    [Nextpeer initializeWithProductKey:Key
                                        andDelegates:[NPDelegatesContainer containerWithNextpeerDelegate:self]];
    
     if( [[TwoDStarUIKitDelegate sharedAppDelegate] HasLauchOption] )
     {
         [Nextpeer handleLaunchOptions: [[TwoDStarUIKitDelegate sharedAppDelegate] GetLauchOption]];
        
     }
}


-(void)nextpeerDidTournamentStartWithDetails:(NPTournamentStartDataContainer *)tournamentContainer
{
   // [Nextpeer openFeedDashboard];
}


-(void)nextpeerDidTournamentEnd
{
    
}

- (BOOL)nextpeerShouldShowWelcomeBanner
{
    return NO; // Show banner
}

- (BOOL)shouldAllowInterGameScreen
{
    return YES;
}

- (void)nextpeerWillHideToShowInterGameScreen
{
    [Nextpeer dismissDashboard];
}

- (void) ReportScore : (int) Score
{
    
    
    if ([Nextpeer isCurrentlyInTournament])
    {
        // Report the score to Nextpeer
        [Nextpeer reportScoreForCurrentTournament:Score];
    }
}

- (void) LaunchDashBoard
{
    [Nextpeer launchDashboard];
}


/**
 This is where OpenGL games should unpause and resume playback.
 */
- (void)nextpeerDashboardDidDisappear
{
    CNextpeerDashboardDidDisappear();
}

/**
 This is where you should pause your game.
 */
- (void)nextpeerDashboardWillAppear
{
    CNextpeerDashboardWillAppear();
}


- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    if ([Nextpeer handleOpenURL:url]) {
        return YES;
    }
    
    // Handle other possible URLS
    
    return NO;
}


- (void) SetCurrentTournament : (NSString*) LevelID
{
    m_CurrentLevelID = LevelID;
}



- (void) ReportForfeitForCurrentTournament
{
    [Nextpeer reportForfeitForCurrentTournament];
}

- (void) ReportControlledTournamentOver:(int) Score
{
    if ([Nextpeer isCurrentlyInTournament])
    {
        [Nextpeer reportControlledTournamentOverWithScore:Score];
    }
}


-(BOOL)nextpeerSupportsTournamentWithId:(NSString* )tournamentUuid
{
    if ([tournamentUuid isEqualToString:m_CurrentLevelID])
    {
        return YES;
    }
    else
    {      
        return NO;
    }
}


@end
